package net.cloudcodex.client.character.presenter;

import net.cloudcodex.client.CloudCodexEventBus;
import net.cloudcodex.client.campaign.view.CampaignsView.Message;
import net.cloudcodex.client.character.view.CharacterInCampaignView;
import net.cloudcodex.client.character.view.CharacterInCampaignViewImpl;
import net.cloudcodex.client.widgets.CharacterAvatar;
import net.cloudcodex.shared.dto.campaign.character.CharacterHeaderDTO;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.inject.Inject;
import com.mvp4g.client.annotation.Presenter;
import com.mvp4g.client.presenter.BasePresenter;

/**
 * 
 * 
 * @author ADaroussin
 */
@Presenter(view = CharacterInCampaignViewImpl.class, multiple = true)
public class CharacterInCampaignPresenter extends
		BasePresenter<CharacterInCampaignView, CloudCodexEventBus> {
	private final Message message;
	private CharacterHeaderDTO characterHeaderDTO;
	private Long campaignId;

	@Inject
	public CharacterInCampaignPresenter(Message pMessage) {
		this.message = pMessage;
	}

	@Override
	public void bind() {
		this.view.getCharacterAvatar().addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				
				CharacterAvatar clickedAvatar = (CharacterAvatar) event
						.getSource();
				eventBus.initCharacterDescription(campaignId,clickedAvatar
						.getId());
			}
		});
	}

	public void addCharacterHeader(Long campaignId , CharacterHeaderDTO characterHeaderDTO) {
		this.characterHeaderDTO = characterHeaderDTO;
		this.campaignId = campaignId ;
	}

	public void initView() {
		this.view.addCharacter(characterHeaderDTO.getId(),
				characterHeaderDTO.getName(), characterHeaderDTO.getIcon(),
				characterHeaderDTO.getOwner() != null);
	}
	
	

}
